package com.bit.frige.DB;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bit.frige.R;

public class MyAdapter3 extends BaseAdapter {
    private Context context;
    private ArrayList<FoodDTO> arrData;
    private LayoutInflater inflater;
    
            public MyAdapter3(Context c, ArrayList<FoodDTO> arr) {
                     this.context = c;
                     this.arrData = arr;
                     inflater = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            }
            public int getCount() {
                    return arrData.size();
            }
            public Object getItem(int position) {
                    return arrData.get(position).getFoodname();
            }
            public long getItemId(int position) {
                    return position;
            }
            public View getView(int position, View convertView, ViewGroup parent) {
                     if(convertView == null){
                      convertView = inflater.inflate(R.layout.listlayout, parent, false);
                     }
             
                     ImageView img = (ImageView)convertView.findViewById(R.id.adapterimg);
                    int cateno = arrData.get(position).getCateno();
            		if (cateno == 0) {
            			img.setImageResource(R.drawable.food1);
            		} else if (cateno == 1) {
            			img.setImageResource(R.drawable.food2);
            		} else if (cateno == 2) {
            			img.setImageResource(R.drawable.food3);
            		} else if (cateno == 3) {
            			img.setImageResource(R.drawable.food4);
            		} else if (cateno == 4) {
            			img.setImageResource(R.drawable.food5);
            		} else if (cateno == 5) {
            			img.setImageResource(R.drawable.food6);
            		} else if (cateno == 6) {
            			img.setImageResource(R.drawable.food7);
            		} else if (cateno == 7) {
            			img.setImageResource(R.drawable.food8);
            		}
                    
                     TextView name = (TextView)convertView.findViewById(R.id.adaptername);
                     name.setText(arrData.get(position).getFoodname());
                     
                    
                     return convertView;
             
            }

   }